﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Catering.View_Operaction;
using Catering_Rules;
using System.Data;
using Microsoft.Reporting.WebForms;
using System.Data.SqlClient;

namespace Catering.Catering_Page.JieGouJianKong
{
    public partial class Jiegoufenxi : System.Web.UI.Page
    {
        private static View_Monitor vm = new View_Monitor();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            string AREAID = UCDDLToolWithYearOfMonth1.GetDDL_Area();
            string CLASSID = UCDDLToolWithYearOfMonth1.GetDDL_Class();
            DateTime DTIME = UCDDLToolWithYearOfMonth1.GetDateTime();
            string TimeType = UCDDLToolWithYearOfMonth1.GetTimeType();
            if (DTIME.Year.Equals(1949))
            {
                return;
            }
            switch (TimeType)
            {
                case "Year":
                    GetDataForYear(AREAID, CLASSID, DTIME);
                    break;
                case "Month":
                    GetDataForMonth(AREAID, CLASSID, DTIME);
                    break;
            }
        }

        private void GetDataForYear(string AREAID, string CLASSID, DateTime DTIME)
        {
            string Title1 = Bind_Data_to_Controls.Bind_ReportTitle(AREAID, CLASSID, DTIME, "五大类食品消耗比例图");
            string Title2 = Bind_Data_to_Controls.Bind_ReportTitle(AREAID, CLASSID, DTIME, "消耗量统计");
            string pid = "0";
            if (Session["UserID"] != null) pid = Session["UserID"].ToString();
            DataTable dt1 = vm.GetTotalPercent(pid, AREAID, CLASSID, DTIME.Year.ToString(), Title1);
            DataTable dt2 = vm.GetTotalPercentMonth(pid, AREAID, CLASSID, DTIME.Year.ToString(), Title2);
            DataTable dt3 = vm.GetTotalPercentStandard();
            ReportDataSource rds = new ReportDataSource("DataSet1", dt1);
            ReportDataSource rds3 = new ReportDataSource("DataSet3", dt3);
            ReportDataSource rds2 = new ReportDataSource("DataSet2", dt2);

            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.ReportPath = @"Catering_Page\JieGouJianKong\Report\TotalPercent_rp.rdlc";
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.DataSources.Add(rds2);
            ReportViewer1.LocalReport.DataSources.Add(rds3);
            ReportViewer1.LocalReport.Refresh();
            ReportViewer1.Visible = true;
        }

        private void GetDataForMonth(string AREAID, string CLASSID, DateTime DTIME)
        {
            string Title1 = Bind_Data_to_Controls.Bind_ReportTitle(AREAID, CLASSID, DTIME, "五大类食品消耗比例图");
            string Title2 = Bind_Data_to_Controls.Bind_ReportTitle(AREAID, CLASSID, DTIME, "消耗量统计");
            string pid = "0";
            if (Session["UserID"] != null) pid = Session["UserID"].ToString();
            DataTable dt1 = vm.GetTotalPercentForMonth(pid, AREAID, CLASSID, DTIME, Title1);
            DataTable dt2 = vm.GetTotalPercentForDay(pid, AREAID, CLASSID, DTIME, Title2);
            DataTable dt3 = vm.GetTotalPercentStandard();
            ReportDataSource rds = new ReportDataSource("DataSet1", dt1);
            ReportDataSource rds3 = new ReportDataSource("DataSet3", dt3);
            ReportDataSource rds2 = new ReportDataSource("DataSet2", dt2);

            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.ReportPath = @"Catering_Page\JieGouJianKong\Report\TotalPercentForMonth.rdlc";
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.DataSources.Add(rds2);
            ReportViewer1.LocalReport.DataSources.Add(rds3);
            ReportViewer1.LocalReport.Refresh();
            ReportViewer1.Visible = true;
        }
    }
}